<?php

/*
  PHPBB Grab logs in and grabs the first thread on a board of threads.
  phpbb_grab(
    Forum Domain (warezbb.org / domain.com/forum)
    Login Extension (login.php)
    Board Number (20)
    Eliminator (Stickies & Announcements Eliminator (make starting point using unique string, seek docs for more info)
    Username
    Password
    BBcode class
  )
  
  VBulletin Grab logs in and grabs the first thread on a board of threads.
  vbulletin_grab(
    Forum Domain (warezbb.org / domain.com/forum)
    Login Extension (login.php?do=login)
    Board (11-applications.html)
    Eliminator (Stickies & Announcements Eliminator (make starting point using unique string, seek docs for more info)
    Username
    Password
    BBcode class
    Offset Thread (Optional, works with eliminator to avoid leeching stickies and announcements, seek docs for more info) (Default = 1)
    Thread URL format (Optional, for "domain.com/apple-mac/wbb-2332-threadtitle.html" the input would be "apple-mac/wbb-[123]-[*]", seek docs for more info)
  )
  
  phpbb_grab("http://www.warez-bb.org/","login.php","viewforum.php?f=5","b>Topics<","user","password",$bbcode);
  vbulletin_grab("aussiewarez.com","login.php?do=login","6","Thread Starter</a","user","password",$bbcode);
  
*/

// Modify BBCodes below.

include('bbcode.class.php'); 
$bbcode = new bbcode(); 
$bbcode->add_tag(array('Name'=>'code','HtmlBegin'=>'<code>','HtmlEnd'=>'</code>')); 
$bbcode->add_tag(array('Name'=>'b','HtmlBegin'=>'<span style="font-weight: bold;">','HtmlEnd'=>'</span>')); 
$bbcode->add_tag(array('Name'=>'i','HtmlBegin'=>'<span style="font-style: italic;">','HtmlEnd'=>'</span>')); 
$bbcode->add_tag(array('Name'=>'u','HtmlBegin'=>'<span style="text-decoration: underline;">','HtmlEnd'=>'</span>')); 
$bbcode->add_tag(array('Name'=>'link','HasParam'=>true,'HtmlBegin'=>'<a href="%%P%%">','HtmlEnd'=>'</a>')); 
$bbcode->add_tag(array('Name'=>'color','HasParam'=>true,'ParamRegex'=>'[A-Za-z0-9#]+','HtmlBegin'=>'<span style="color: %%P%%;">','HtmlEnd'=>'</span>','ParamRegexReplace'=>array('/^[A-Fa-f0-9]{6}$/'=>'#$0'))); 
$bbcode->add_tag(array('Name'=>'email','HasParam'=>true,'HtmlBegin'=>'<a href="mailto:%%P%%">','HtmlEnd'=>'</a>')); 
$bbcode->add_tag(array('Name'=>'size','HasParam'=>true,'HtmlBegin'=>'<span style="font-size: %%P%%pt;">','HtmlEnd'=>'</span>','ParamRegex'=>'[0-9]+')); 
$bbcode->add_tag(array('Name'=>'bg','HasParam'=>true,'HtmlBegin'=>'<span style="background: %%P%%;">','HtmlEnd'=>'</span>','ParamRegex'=>'[A-Za-z0-9#]+')); 
$bbcode->add_tag(array('Name'=>'s','HtmlBegin'=>'<span style="text-decoration: line-through;">','HtmlEnd'=>'</span>')); 
$bbcode->add_tag(array('Name'=>'align','HtmlBegin'=>'<div style="text-align: %%P%%">','HtmlEnd'=>'</div>','HasParam'=>true,'ParamRegex'=>'(center|right|left)')); 
$bbcode->add_tag(array('Name'=>'img','HtmlBegin'=>'<img class="magnify" src="','HtmlEnd'=>'" alt="image" />')); 
$bbcode->add_tag(array('Name'=>'quote','HtmlBegin'=>'<div class="quotebox">','HtmlEnd'=>'</div>')); 
$bbcode->add_tag(array('Name'=>'center','HtmlBegin'=>'<div style="align:center">','HtmlEnd'=>'</div>')); 
					
include('phpbb.class.php');
include('vbulletin.class.php');
include('htmlparse.php');

function phpbb_grab($domain,$loginext,$board,$eliminator,$username,$password,$bbcode){    
  $domain = "http://$domain/";
	$phpbb = new curl_phpbb($domain); 
	$htmlparse = new HTMLParse();
	// perform login
	$phpbb->login($username, $password, $loginext); 
	// get threadlist source
	$source = $phpbb->read($board);
	$source = substr($source,strpos($source,$eliminator));
	// get thread list links only
	$threads = implode($htmlparse->GetInnerArrayFilter($source, "td", "align", ""));
	$titles = $htmlparse->GetInnerArray("a", $threads);
	$count = 0; $post_title = ""; $post_body = "";
	foreach($titles as $title){
			$i = $htmlparse->GetTagAttribute($threads, "a", "href");
			$source = $phpbb->read(trim($i[$count],'.'));
			$post_title = $title;
			$links = $htmlparse->GetTagAttribute($source, "a", "href");
			foreach($links as $link){
				if(substr(trim($link,"./"),0,22)=="posting.php?mode=quote"){
					$source = $phpbb->read(trim($link,'.'));
					$textarea = $htmlparse->GetInnerArray("textarea",$source);
					$post_body = $textarea[0];
					$post_body = substr($post_body,strpos($post_body,']')+1);
					$post_body = substr($post_body,0,strrpos($post_body,'['));			
					$post_body = nl2br($this->$bbcode->parse_bbcode($post_body));
					break;
				}
			}
			break;
		$count++;
	}
	$postbody = $htmlparse->GetInnerArrayFilter($source,"div","class","postbody");
	$phpbb->logout(); 
	 echo urldecode($post_title).urldecode($post_body);
}

vbulletin_grab("downw.org","login.php?do=login","apple-mac/","Thread Starter</a","theforumdrunk","kitten",$bbcode,1,"[123]-[*]");
function vbulletin_grab($domain,$loginext,$board,$eliminator,$username,$password,$bbcode,$offset=1,$urlformat="showthread.php?[123]-[*]"){    
  $domain = "http://$domain/";
	$vbulletin = new curl_vbulletin($domain); 
	$htmlparse = new HTMLParse();
	// perform login
	$vbulletin->login($username, $password, $loginext); 
	// get threadlist source
	$source = $vbulletin->read($board);
	$source = substr($source,strpos($source,$eliminator));
	// get thread list links only
	$threads = implode($htmlparse->GetInnerArrayFilter($source, "h3", "class", "threadtitle"));
	$threadlink = $htmlparse->GetTagAttribute($threads, "a", "href");
	$threadtitle = $htmlparse->GetInnerArray("a", $threads);
	$count = $offset; $post_title = ""; $post_body = "";
	
	foreach($threadlink as $link){
    $post_title = $threadtitle[($count-1)+$count];
    $threadnumber = $threadlink[($count-1)+$count];   
    $threadnumber = str_replace($threadnumber,substr($threadnumber,0,strpos($urlformat,"[123]")),"");
    $threadnumber = substr($threadnumber,0,strpos($threadnumber,substr($urlformat,5,1)));
  	$replylink = "newreply.php?do=newreply&p=$threadnumber";
    $source = $vbulletin->read($replylink);
    $textarea = $htmlparse->GetInnerArray("textarea",$source);
    $post_body = $textarea[0];
    $post_body = substr($post_body,strpos($post_body,']')+1);
    $post_body = substr($post_body,0,strrpos($post_body,'['));
    $post_body = nl2br($bbcode->parse_bbcode($post_body));
    
  	$postbody = $htmlparse->GetInnerArrayFilter($source,"div","class","postbody");
  	$vbulletin->logout(); 
  	echo urldecode($post_title)."<br />".urldecode($post_body);
  	$count++;
  	break;
	}
}

?>